import { type SupplierItemType } from "./../supplier/supplier";
import request, { type ListResponse, type ListQuery } from "@/utils/request";

const BASE_URL = "/api/internal/DiscountCoupon/";

export const CouponAPI = {
  getCouponList: (params: ListQuery) => {
    return request.get<any, ListResponse<CouponType>>(`${BASE_URL}/`, {
      params,
    });
  },
  getCouponDetail: (id: number) => {
    return request.get(`${BASE_URL}/${id}/`);
  },
  createCoupon: (data: Partial<CouponForm>) => {
    return request.post(`${BASE_URL}/`, data);
  },
  updateCoupon: (data: Partial<CouponForm>) => {
    return request.put(`${BASE_URL}/${data.id}/`, data);
  },
  deleteCoupon: (id: number) => {
    return request.delete(`${BASE_URL}/${id}/`);
  },
};

export type CouponListQuery = {} & ListQuery;

export type CouponType = {
  id: number;
  supplier: SupplierItemType;
  created_at: string;
  updated_at: string;
  is_active: boolean;
  name: string;
  amount: string;
  min_purchase: string;
  start_at: string;
  end_at: string;
  expired_at: string;
  valid_days: number;
  usage_limit: number;
  total_limit: number;
  remaining_quantity: number;
  remark: string;
};

export type CouponForm = {
  id?: number;
  supplier: number | string;
  is_active: boolean;
  name: string;
  amount: number;
  min_purchase: number;
  start_at: string;
  end_at: string;
  expired_at: string;
  valid_days: number;
  usage_limit: number;
  total_limit: number;
  remaining_quantity: number;
  remark: string;
};

export default CouponAPI;
